package xperiment.metaphor.model.entity;

import xperiment.metaphor.model.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * The grade of the job
 * 
 * @author Mark Ashworth
 * @version 1.0.0
 */
@Entity
@Table(name="grade")
public class Grade extends AbstractBean implements Persistent, Named {

	/** The grade unique id */
	@Id @GeneratedValue(strategy=GenerationType.AUTO) 
    @Column(name = "grade_id", unique = true, nullable = false)
    private Long id = null;
    
    /* The name of the grade */
    @Column(name="grade_name", nullable=false, unique=true, length=50)
    private String name;
   
    /* Whether the grade is enabled */
    @Column(name = "enabled", nullable = false)
    private boolean enabled = true;
    
    /**
     * Default constructor
     */
    public Grade() {
        super();
    }
    
    /**
     * Constructs the grade with it's name
     * @param name The name of the grade
     */
    public Grade(String name) {
        super();
        this.name = name;
    }
    
    /**
     * The grade unique id
     * @return Long
     */
    @Override
	public Long getId() {
		return this.id;
	}

    /**
     * The name of the grade
     * @return String 
     */
	@Override
	public String getName() {
		return this.name;
	}

    /**
     * Whether the grade is enabled
     * @return boolean
     */
    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    /**
     * Returns the name as the representation of the grade
     * @return String
     */
    public String toString() {
        return getName();
    }
    
    /**
     * &lt;grade class="xperiment.metaphor.model.people.employee.Grade" name="Management"/&gt;
     * @return String
     */
    public String toXML() {
        return "<grade class='" + getClass().getName() 
                + "' id='" + getId() 
                + "' name='" + getName() 
                + "' enabled='" + isEnabled() 
                + "' />";
    }

    /**
     * Calculates the equality based upon the name of the grade
     * @param obj The other object
     * @return boolean
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Grade other = (Grade) obj;
        if (this.name != other.name && (this.name == null || !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    /**
     * Calculates the hash code on the name
     * @return int
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }
}
